package com.humdeef.socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 传统型socket
 */
public class TransactionSocketDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("服务端启动。。。");
        while (true) {
            Socket socket = serverSocket.accept();   //阻塞点1
            System.out.println("有新的客户端连接上来了。。。。");
            InputStream inputStream = socket.getInputStream();
            byte [] bytes = new byte[1024];
            while (true){
                int data = inputStream.read();  //阻塞点2
                if(data!=-1){
                    String info  = new String( bytes,0,data);
                    System.out.println("服务端接收的到的消息:"+info);
                }else {
                    break;
                }
            }
        }
    }
}
